package com.houdoudou.bean;

import javax.servlet.http.HttpServletRequest;

public class Financer {

	 String telnum="";
	   String secret="";
	   int type=2;
	public Financer() {
		
	}

	public Financer(String telnum, String secret, int type) {
		super();
		this.telnum = telnum;
		this.secret = secret;
		this.type = type;
	}

	public int getType() {
		return type;
	}

	public void setType(int type) {
		this.type = type;
	}

	public String getTelnum() {
		return telnum;
	}

	public void setTelnum(String telnum) {
		this.telnum = telnum;
	}

	public String getSecret() {
		return secret;
	}

	public void setSecret(String secret) {
		this.secret = secret;
	}

	public static Financer beanFromRequest(HttpServletRequest req) throws Exception {
		
		Financer financer= new Financer();
		if(req.getParameter("secret")!=null){	
				financer.setSecret(req.getParameter("secret"));
	           }
		if(req.getParameter("telnum")!=null){	
				financer.setTelnum(req.getParameter("telnum"));
	           }
		if(req.getParameter("type")!=null){		
				int type=Integer.parseInt(req.getParameter("type"));
				financer.setType(type);
	           }
		System.out.println("FinancerBean  "+"secret="+financer.getSecret()+"   telnum="+financer.getTelnum()+"   type="+financer.getType());
		return financer;
	}

	public static  Financer merge(Financer financerExist, Financer financerGiven){
		
		if(financerGiven.getSecret()!=null){	
			if(!financerGiven.getSecret().isEmpty()){
				financerExist.setSecret(financerGiven.getSecret());
			}
		}		
			if(financerGiven.getType()!=2){
				financerExist.setType(financerGiven.getType());
			}

		
		return financerExist;
	}		
	
	public static  Financer encrypt(Financer financer) throws Exception{
		 String ciphertext = PasswordUtil.encrypt(financer.getSecret());  
		        financer.setSecret(ciphertext);
		return financer;
	}
	
}
